import Vue from "vue";
// 时间格式化；
Vue.prototype.formatTime = function (time){
    let date = new Date(time);
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    let D = (date.getDate() < 10 ? '0'+ (date.getDate()) : date.getDate()) + ' ';
    let h = (date.getHours() < 10 ? '0'+ (date.getHours()) : date.getHours()) + ':';
    let m = (date.getMinutes() < 10 ? '0'+ (date.getMinutes()) : date.getMinutes()) + ':';
    let s = (date.getSeconds() < 10 ? '0'+ (date.getSeconds()) : date.getSeconds());
    return Y+M+D+h+m+s;
};

Vue.prototype.formatDate = function (time){
    let date = new Date(time);
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    let D = (date.getDate() < 10 ? '0'+ (date.getDate()) : date.getDate()) + ' ';
    return Y+M+D;
};

Vue.prototype.getCookie = function (name){
    name = name + "=";
    let start = document.cookie.indexOf(name);
    let value = null;
    if(start>-1){
        let end = document.cookie.indexOf(";",start);
        if(end === -1){
            end = document.cookie.length;
        }
        value = document.cookie.substring(start+name.length,end);
    }
    return value;
};

Vue.prototype.isNumeric = function (n){
    return !isNaN(parseFloat(n)) && isFinite(n);
};

export default Function;
